var mainPlatform = {

    init: function () {

        this.bindEvent();
        // this.render(menu['home']);
    },

    bindEvent: function () {
        var self = this;
        // 顶部大菜单单击事件
         $(document).on('click', '.pf-nav-item', function () {
        	
            $('.pf-nav-item').removeClass('current');
            $(this).addClass('current');
            // 渲染对应侧边菜单
            //var m = $(this).data('menu');
            //self.render(menu[m]);

            //my
            var pid = $(this).attr('data-pid');
            var pname = $(this).attr('data-pname');
            $.ajax({
                url: "/Home/GetLeftMenu",    //请求的url地址
                dataType: "json",   //返回格式为json
                async: true,//请求是否异步，默认为异步，这也是ajax重要特性
                data: { topMenuId: pid },    //参数值
                type: "GET",   //请求方式
                beforeSend: function () {
                    //请求前的处理
                },
                success: function (data) {
                    //请求成功时处理
                    var content = '<a href="javascript:;">' +
                                    '<span class="iconfont sider-nav-icon">&#xe620;</span>' +

                                    '<span class="sider-nav-title">' + pname + '</span>' +
                                    '<i class="iconfont">&#xe642;</i>' +
                                '</a>';
                    if (data != null && data.length > 0) {
                        content += '<ul class="sider-nav-s">';
                        $.each(data, function (index, item) {
                            content += '<li onclick="kidMenuClick(this)" data-href="' + item.Url + '" data-name="' + item.Name + '" style="cursor:pointer"><a>' + item.Name + '</a></li>';
                        });
                        content += '</ul>';
                    }
                    $("#left_kids").html(content);
                },
                complete: function () {
                    //请求完成的处理
                },
                error: function () {
                    //请求出错处理
                }
            });
        });
		//左侧可以点击的内容
        $(document).on('click', '.sider-nav li', function () {
            $('.sider-nav li').removeClass('current');
            $(this).addClass('current');
            console.log($('iframe'));
            $('iframe').attr('src', $(this).data('src'));
        });

		//退出按钮
        $(document).on('click', '.pf-logout', function () {
            layer.confirm('您确定要退出吗？', {
                icon: 4,
                title: '确定退出' //按钮
            }, function () {
                location.href = '/home/logout';
            });
        });
        //左侧菜单收起
        $(document).on('click', '.toggle-icon', function () {
            $(this).closest("#pf-bd").toggleClass("toggle");
            setTimeout(function () {
                $(window).resize();
            }, 300)
        });

      
      
        //$(window).resize(function () {
        //    $('#home_tabs').tabs("resize");
        //}).resize();

        //$(document).on('click', '.pf-modify-pwd', function () {
        //    $('#pf-page').find('iframe').eq(0).attr('src', 'backend/modify_pwd.html')
        //});

        //$(document).on('click', '.pf-notice-item', function () {
        //    $('#pf-page').find('iframe').eq(0).attr('src', 'backend/notice.html')
        //});
    },

    render: function (menu) {
        var current,
			html = ['<h2 class="pf-model-name"><span class="pf-sider-icon"></span><span class="pf-name">' + menu.title + '</span></h2>'];

        html.push('<ul class="sider-nav">');
        for (var i = 0, len = menu.menu.length; i < len; i++) {
            if (menu.menu[i].isCurrent) {
                current = menu.menu[i];
                html.push('<li class="current" title="' + menu.menu[i].title + '" data-src="' + menu.menu[i].href + '"><a href="javascript:;"><img src="' + menu.menu[i].icon + '"><span class="sider-nav-title">' + menu.menu[i].title + '</span><i class="iconfont"></i></a></li>');
            } else {
                html.push('<li data-src="' + menu.menu[i].href + '" title="' + menu.menu[i].title + '"><a href="javascript:;"><img src="' + menu.menu[i].icon + '"><span class="sider-nav-title">' + menu.menu[i].title + '</span><i class="iconfont"></i></a></li>');
            }
        }
        html.push('</ul>');

        $('iframe').attr('src', current.href);
        $('#pf-sider').html(html.join(''));
    }

};

mainPlatform.init();

//左侧菜单点击事件
function kidMenuClick(ctr) {
    var url = $(ctr).attr("data-href");
    var name = $(ctr).attr("data-name");
    if ($("#home_tabs").tabs('exists', name)) {
        $('#home_tabs').tabs('select', name);
    } else {
        //if (url.toLowerCase().indexOf("roompattern") > 0) {
        //    //房态图，不需每次刷新
        //    $('#home_tabs').tabs('add', {
        //        title: name,
        //        closable: true,
        //        href: url,
        //        style: { padding: "5px" },
        //    });
        //}
        
        //else {
        //    var content = '<iframe class="" src="' + url + '" frameborder="no" border="no" height="100%" width="100%" scrolling="auto"></iframe>';
        //    $('#home_tabs').tabs('add', {
        //        title: name,
        //        closable: true,
        //        //href: url,
        //        style: { padding: "5px" },
        //        content: content
        //    });
        //}
        var content = '<iframe class="" src="' + url + '" frameborder="no" border="no" height="100%" width="100%" scrolling="auto"></iframe>';
        $('#home_tabs').tabs('add', {
            title: name,
            closable: true,
            //href: url,
            style: { padding: "0px" },
            content: content
        });
    }
}


//用户信息
function userMenuClick(url,name) {
    if ($("#home_tabs").tabs('exists', name)) {
        $('#home_tabs').tabs('select', name);
    } else {
       
        var content = '<iframe class="" src="' + url + '" frameborder="no" border="no" height="100%" width="100%" scrolling="auto"></iframe>';
        $('#home_tabs').tabs('add', {
            title: name,
            closable: true,
            //href: url,
            style: { padding: "0px" },
            content: content
        });
    }
}

//判断是否是IE<10的版本  
function isOldIE() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串  
    var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器 
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器  
    var isEdge = userAgent.indexOf("Windows NT 6.1; Trident/7.0;") > -1 && !isIE; //判断是否IE的Edge浏览器  
    if (isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        if (fIEVersion == 10 || fIEVersion == 11) {
            return false
        } else {
            return true;
        }
    }
    else {
        return false;//非IE  
    }
}
$.extend({
    includePath: '',
    include: function (file) {
        var files = typeof file == "string" ? [file] : file;
        for (var i = 0; i < files.length; i++) {
            var name = files[i];
            var att = name.split('.');
            var ext = att[att.length - 1].toLowerCase();
            var isCSS = ext == "css";
            var tag = isCSS ? "link" : "script";
            var attr = isCSS ? " type='text/css' rel='stylesheet' " : " language='javascript' type='text/javascript' ";
            var link = (isCSS ? "href" : "src") + "='" + $.includePath + name + "'";
            if ($(tag + "[" + link + "]").length == 0) document.write("<" + tag + attr + link + "></" + tag + ">");
        }
    }
});

